let li1 = document.getElementById("n1");
let li2 = document.getElementById("n2");
let li3 = document.getElementById("n3");
let li4 = document.getElementById("n4");

let list1 = document.getElementById("No1");
let list2 = document.getElementById("No2");
let list3 = document.getElementById("No3");
let list4 = document.getElementById("No4");

function show(x, y) {


    li1.style['background'] = "white"
    li1.style['border-bottom'] = "0px"

    li2.style['background'] = "white"
    li2.style['border-bottom'] = "0px"

    li3.style['background'] = "white"
    li3.style['border-bottom'] = "0px"

    li4.style['background'] = "white"
    li4.style['border-bottom'] = "0px"

    x.style['background'] = "white"
    x.style['border-bottom'] = "3px solid #D7AD53"

    /*公告新闻。。。隐藏显示 */

    list1.style.display = "none"
    list2.style.display = "none"
    list3.style.display = "none"
    list4.style.display = "none"

    document.getElementById("No" + y).style.display = "block"
}

let pre_img = 1

function img_move(x, y) {
    let move = (x - pre_img) * -550
    let img_box = document.getElementById("img-box")

    img_box.style.left = move + "px"
    console.log(move)
    console.log(img_box)

    let button = document.getElementById("button").getElementsByTagName("li")
    for (let i = 0; i < button.length; i++) {
        button[i].classList.remove("change")
    }
    y.classList.add("change")
    console.log(button)
}

let next_btn = document.getElementById("next");
let pre_btn = document.getElementById("pre");
let index = 0
let status = false
let auto =null
let page = document.getElementById("lunbo2-ul").getElementsByTagName("li")
let lunbo2 = document.getElementById("lunbo2")
next_btn.onclick = () => {
    if (status) {
        return false
    }

    let new_index = index + 1 > 3 ? 0 : index + 1;
    console.log(new_index)
    animation(new_index)
}


pre_btn.onclick = () => {
    if (status) {
        return false
    }
    let new_index = index - 1 < 0 ? 3 : index - 1;
    animation(new_index)
}

function animation(new_index) {
    console.log(new_index)
    status = true;

    let interval = 10
    let offset = 1 / (1000 / interval)

    for (let i = 0; i < page.length; i++) {
        page[i].style.zIndex = -1
    }

    page[index].style.zIndex = 1;
    page[new_index].style.zIndex = 0;

    page[new_index].style.opacity = 0;

    function go(){
        let opacity = parseFloat(page[index].style.opacity);
        opacity-=offset
        page[index].style.opacity = opacity;

        let opacity2 = parseFloat(page[new_index].style.opacity)
        opacity2+=offset
        page[new_index].style.opacity = opacity2

        if(opacity<=0){
            page[0].style.opacity = 0

            for(let i=0;i<page.length;i++){
                page[i].style.zIndex='-1'
                page[i].style.opacity = 1
            }

            page[new_index].style.zIndex= 1
            index =new_index
            status =false
        }else{
            setTimeout(()=>{
                go()
            },interval)
        }
    }
    go()
}
/*轮播自动播放*/ 
function autoPlay(){
    auto = setInterval(() => {
        next_btn.onclick();
    }, 3000);
}

lunbo2.onmouseover = ()=>{
    clearInterval(auto)
}
lunbo2.onmouseout = ()=>{
    autoPlay()
}
autoPlay()

/*关闭右侧广告 */

function distory(){
    
    let ad = document.getElementsByClassName("float-right")[0]
    ad.style.display="none"
}